package org.apache.ibatis.test_clxmm.test03_cache;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.test_clxmm.test03_cache.entity.User;
import org.apache.ibatis.test_clxmm.test03_cache.mapper.UserMapper;
import org.apache.ibatis.test_clxmm.test03_cache.util.SqlSessionUtil;
import org.junit.jupiter.api.Test;

import java.util.List;

public class Main1Level1 {


  @Test
  public void test1() {


    try (SqlSession sqlSession = SqlSessionUtil.getSqlSession()) {
      UserMapper mapper = sqlSession.getMapper(UserMapper.class);

      System.out.println("fir:findAll ");
      mapper.findAll();

      System.out.println("sec:findAll ");
      // 一级缓存生效
      mapper.findAll();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }


  @Test
  public void test2() {


    try (SqlSession sqlSession = SqlSessionUtil.getSqlSession()) {
      UserMapper mapper = sqlSession.getMapper(UserMapper.class);

      System.out.println("fir:findAll ");
      mapper.findAll();

      System.out.println("sec:findAll ");
      // 一级缓存生效
      mapper.findAll();

      // flushCache 这个属性时提到过，它可以清空一级缓存和它所属的 namespace 下的二级缓存
      mapper.cleanCache();

      System.out.println("3:findAll ");

      mapper.findAll();


    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  // 一级缓存实现
  // 1。跨SqlSession的一级缓存不共享
  // 2。两次相同的查询间有DML操作，insert 、update 、delete 标签的 flushCache 默认为 true ，
  // 3。手动清空了一级缓存

















}
